package com.specialized.passenger.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.specialized.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.specialized.common.log.annotation.Log;
import com.specialized.common.log.enums.BusinessType;
import com.specialized.common.security.annotation.RequiresPermissions;
import com.specialized.passenger.domain.Coupons;
import com.specialized.passenger.service.ICouponsService;
import com.specialized.common.core.web.controller.BaseController;
import com.specialized.common.core.utils.poi.ExcelUtil;

/**
 * 个人优惠券Controller
 *
 * @author djh
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/coupons")
public class CouponsController extends BaseController {
    @Autowired
    private ICouponsService couponsService;

    /**
     * 查询个人优惠券列表
     */
    @GetMapping("/list")
    public Result list(Coupons coupons) {
        startPage();
        List<Coupons> list = couponsService.selectCouponsList(coupons);
        return getDataTable(list);
    }

    /**
     * 导出个人优惠券列表
     */
    @Log(title = "个人优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Coupons coupons) {
        List<Coupons> list = couponsService.selectCouponsList(coupons);
        ExcelUtil<Coupons> util = new ExcelUtil<Coupons>(Coupons. class);
        util.exportExcel(response, list, "个人优惠券数据");
    }

    /**
     * 获取个人优惠券详细信息
     */
    @GetMapping(value = "/{userCouponId}")
    public Result getInfo(@PathVariable("userCouponId") Long userCouponId) {
        return success(couponsService.selectCouponsByUserCouponId(userCouponId));
    }

    /**
     * 新增个人优惠券
     */
    @Log(title = "个人优惠券", businessType = BusinessType.INSERT)
    @PostMapping("/insertCoupon")
    public Result add(@RequestBody Coupons coupons) {
        return toAjax(couponsService.insertCoupons(coupons));
    }

    /**
     * 修改个人优惠券
     */
    @Log(title = "个人优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Coupons coupons) {
        return toAjax(couponsService.updateCoupons(coupons));
    }

    /**
     * 删除个人优惠券
     */
    @Log(title = "个人优惠券", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userCouponIds}")
    public Result remove(@PathVariable Long[] userCouponIds) {
        return toAjax(couponsService.deleteCouponsByUserCouponIds(userCouponIds));
    }
}
